package com.yuan;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 所有的get请求被调用前在控制台输出一句"get请求的advice触发了"。
 *
 * @Author yuan
 * @Date 2021/9/9 14:06
 */
@Aspect
@Component
@Order(1)
public class LogAdvice {


    /**
     * 所有的get请求被调用前在控制台输出一句"get请求的advice触发了"。
     */
    @Pointcut("@annotation(org.springframework.web.bind.annotation.GetMapping)")
    private void logAdvicePointCut() {
    }

    @Pointcut("@annotation(org.springframework.web.bind.annotation.PostMapping)")
    private void logAdvicePointCut2() {
    }

    /**
     * Before表示logAdvice将在目标方法执行前执行
     */
    @Before("logAdvicePointCut()")
    public void logAdvice() {
        System.out.println("get请求的advice触发了");
    }

    @Before("logAdvicePointCut2()")
    public void logAdvice2() {
        System.out.println("post请求的advice触发了");
    }
    @After("logAdvicePointCut2()")
    public void logAdvice3() {
        System.out.println("post请求的advice触发了之后打印日志");
    }



}
